﻿#include "mainwindow.h"
#include "tcmath.h"
#include "ui_mainwindow.h"
#include <QtWidgets>
#include <QDate>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->pApplication = NULL;
    this->pWorkBooks = NULL;
    this->pWorkBoos = NULL;
    this->pSheets = NULL;
    this->pSheet = NULL;
    this->pWord=NULL;
    this->pDocuments=NULL;
    this->pDocument=NULL;
    ishasOrc = false;
    targetUrl = ui->lineEdit_6->text();


}

MainWindow::~MainWindow()
{
    delete ui;
}

//点击设置审批表位置

void MainWindow::on_Btnorc_clicked()
{
    if(ishasOrc)
    {

    }

    QString lineAdress = this->ui->lineEdit->text();
    QString carAdress = this->ui->lineEdit_2->text();
    this->orcfileUrl = QFileDialog::getOpenFileName(this," \xe4\xba\xa7\xe6\x9d\x83\xe5\xae\xa1\xe6\x89\xb9\xe8\xa1\xa8","","Xlsx(*.xlsx)");
    if (orcfileUrl.isEmpty())
    {
       return;

    }
    HouseProList.clear();
    Document xlsx(orcfileUrl);
    QStringList slist= xlsx.sheetNames();
    //slist.size()
    QLabel* ptipLabel;
    QString ptipStr;
    for(int i=0;i<slist.size();++i)
    {

        QString shename = slist.at(i);
        //判断类型 1住宅 2车位 3商铺
        int buildingType = 1;//默认住宅
        ptipLabel= NULL;
        if(shename.contains("\xe6\x91\xa9\xe6\x89\x98\xe8\xbd\xa6") || shename.contains("\xe8\xbd\xa6\xe4\xbd\x8d"))
        {
            buildingType =2;
            ptipLabel = ui->label_cw;
            ptipStr="\xe8\xbd\xa6\xe4\xbd\x8d\xe6\x95\xb0\xe9\x87\x8f\xef\xbc\x9a";
            if(shename.contains("\xe6\x91\xa9\xe6\x89\x98\xe8\xbd\xa6"))
            {
                ptipLabel = ui->label_mtc;
                ptipStr="\xe6\x91\xa9\xe6\x89\x98\xe8\xbd\xa6\xe4\xbd\x8d\xe6\x95\xb0\xe9\x87\x8f\xef\xbc\x9a";
            }
        }
        else if (shename.contains("\xe5\x95\x86\xe9\x93\xba"))
        {
            ptipLabel = ui->label_sp;
            buildingType =3;
            ptipStr = "\xe5\x95\x86\xe9\x93\xba\xe6\x95\xb0\xe9\x87\x8f\xef\xbc\x9a";
        }
        else if(shename.contains("\xe4\xbd\x8f\xe5\xae\x85"))
        {
            ptipLabel = ui->label_zz;
            ptipStr="\xe4\xbd\x8f\xe5\xae\x85\xe6\x95\xb0\xe9\x87\x8f\xef\xbc\x9a";
        }




        QXlsx::Worksheet* ws = (QXlsx::Worksheet*)xlsx.sheet(shename);
        //qDebug()<<ws->read(2,2).toString()<<" 开始行："<<ws->dimension().firstColumn()<<" 开始列："<<ws->dimension().firstRow() <<" 列数:"<<ws->dimension().columnCount()<<" 行数:"<<ws->dimension().rowCount();
        int rowcount =ws->dimension().rowCount();
        int colcount = ws->dimension().columnCount();
        qDebug()<<shename<<" row:"<<rowcount<<" col:"<<colcount;
        if(rowcount<=0 || colcount <=0)
        {
            continue;
        }


        //获取下标位置
        int roomnum =0;
        int pay = 0;
        int cus =0;
        int card = 0;
        int adress =0;
        int phone = 0;
        int house = 0;
        int building =0;
        int indsier = 0;
        int share = 0;
        int servier =0;
        int level = 0;
        int amount = 0;
        int tdsyzh =0;
        int fdcqzh =0;
        int gzrq=0;
        int fwlx=0;
        int szc=0;
        //
        for(int i=1;i<=colcount;i++)
        {
            QString value = ws->read(2,i).toString();
            qDebug()<<value<<"  "<<value.contains("\xe5\x9c\xa8\xe5\xb1\x82",Qt::CaseInsensitive);

            if(value.contains("\xe6\x88\xbf\xe5\x8f\xb7",Qt::CaseInsensitive) || value.contains("\xe8\xbd\xa6\xe4\xbd\x8d\xe5\x8f\xb7",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"roomnum";
                roomnum = i;
            }
            else if(value.contains("\xe5\x90\x8d\xe5\xad\x97",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"cus";
                cus = i;
            }
            else if(value.contains("\xe4\xbb\x98\xe6\xac\xbe\xe6\x96\xb9\xe5\xbc\x8f",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"pay";
                pay=i;
            }
            else if(value.contains("\xe8\xba\xab\xe4\xbb\xbd\xe8\xaf\x81",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"card";
                card =i;
            }
            else if(value.contains("\xe8\x81\x94\xe7\xb3\xbb\xe5\x9c\xb0\xe5\x9d\x80",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"adress";
                adress = i;
            }
            else if(value.contains("\xe6\x88\xbf\xe5\xb1\x8b\xe5\xba\xa7\xe8\x90\xbd",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"house";
                house = i;
            }
            else if(value.contains("\xe8\x81\x94\xe7\xb3\xbb\xe7\x94\xb5\xe8\xaf\x9d",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"phone";
                phone = i;
            }
            else if(value.contains("\xe5\xbb\xba\xe7\xad\x91\xe9\x9d\xa2\xe7\xa7\xaf",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"building";
                building = i;
            }
            else if(value.contains("\xe5\xa5\x97\xe5\x86\x85\xe9\x9d\xa2\xe7\xa7\xaf",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"indsier";
                indsier = i;
            }
            else if(value.contains("\xe5\x88\x86\xe6\x91\x8a\xe9\x9d\xa2\xe7\xa7\xaf",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"share";
                share = i;
            }
            else if(value.contains("\xe6\x9c\x8d\xe5\x8a\xa1\xe8\xb4\xb9",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"servier";
                servier = i;
            }
            else if(value.contains("\xe5\xb1\x82\xe6\x95\xb0",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"level";
                level = i;
            }
            else if(value.contains("\xe6\x88\xbf\xe6\xac\xbe",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"amount";
                amount = i;
            }
            else if(value.contains("\xe5\x9c\x9f\xe5\x9c\xb0\xe4\xbd\xbf\xe7\x94\xa8\xe8\xaf\x81\xe5\x8f\xb7",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"tdsyzh";
                tdsyzh = i;
            }
            else if(value.contains("\xe6\x88\xbf\xe5\x9c\xb0\xe4\xba\xa7\xe6\x9d\x83\xe8\xaf\x81\xe5\x8f\xb7",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"fdcqzh";
                fdcqzh = i;
            }
            else if(value.contains("\xe6\x97\xa5\xe6\x9c\x9f",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"gzrq";
                gzrq = i;
            }
            else if(value.contains("\xe7\xb1\xbb\xe5\x9e\x8b",Qt::CaseInsensitive))
            {
                qDebug()<<value<<"fwlx";
                fwlx = i;
            }
            else if(value.contains("\xe5\x9c\xa8\xe5\xb1\x82",Qt::CaseInsensitive))
            {
                szc = i;
                qDebug()<<"=======================";
            }

        }
        //qDebug()<<roomnum<< "  "<< cus<<"  "<<phone;

        //进度条
        QProgressDialog process(this);
        QString dlabel = "\xe6\xad\xa3\xe5\x9c\xa8\xe8\xaf\xbb\xe5\x8f\x96 ";
        dlabel.append(shename);
        dlabel.append(" \xe6\x95\xb0\xe6\x8d\xae");
        process.setLabelText(dlabel);
        process.setRange(3,rowcount);
        process.setModal(true);
        process.setCancelButtonText("\xe5\x8f\x96\xe6\xb6\x88");

        int countNum = 0;
        //开始保存数据
        qDebug()<<"row:"<<rowcount<<"  -ct:"<<countNum;
        for(int i=3;i<=rowcount;i++)
        {
            if(ws->read(i,1).toString().isEmpty())
            {
                qDebug()<<"sheet NULL";
                continue;
            }

            countNum++;
            process.setValue(i);
            if(process.wasCanceled())
            {
                countNum=0;
                break;
            }


            HousePropertyVO* pHous = new HousePropertyVO();
            HouseProList.append(pHous);
            //房间号,车位号
            QString str= ws->read(i,roomnum).toString();
            pHous->buildNum = str;
            QStringList qs = str.split("_");
            if(qs.count()==2)
            {
                pHous->unitNum = qs.at(0);
                pHous->houseNum = qs.at(1);
            }
             //电话
             QString ltr = ws->read(i,phone).toString();
             QStringList ql=ltr.split("\n");
             ltr=ltr.replace("\n"," ");

             pHous->phone = ql.at(0);
             //姓名
             str= ws->read(i,cus).toString();
             pHous->cusNameStr.append(str);
             QStringList namelist = str.split("\n");
             //身份证
             ltr = ws->read(i,card).toString();
             pHous->cardStr.append(ltr);
             QStringList cardlist = ltr.split("\n");
             for(int j=0;j<namelist.count();j++)
             {
                 QString ns = namelist.at(j);
                 CustomerVO* cv = new CustomerVO();
                 cv->Name = ns;
                 if(j<cardlist.count())
                 {
                     cv->CardNum = cardlist.at(j);
                 }
                 //2014年04月20日

                 QString ol = cv->CardNum.mid(6,8);
                 cv->bridDate = ol.insert(4,"年");
                 cv->bridDate = cv->bridDate.insert(7,"月");
                 cv->bridDate = cv->bridDate.insert(10,"日");
                 //
                 //年龄
                 ol= ol.mid(0,4);
                 QDate nowDate = QDate::currentDate();
                 int old =   nowDate.year()-ol.toInt();
                 cv->old = QString::number(old);
                 //性别
                 QString sexstr = cv->CardNum.right(2);
                 sexstr = sexstr.left(1);
                 int sex = sexstr.toInt();
                 qDebug()<<"\xe6\x80\xa7\xe5\x88\xab\xe6\x95\xb0\xe5\xad\x97:"<<sex;
                 if(sex &1)
                 {
                     cv->sex="\xe7\x94\xb7";
                     qDebug()<<"\xe7\x94\xb7\xe6\x80\xa7";
                 }
                 else
                 {

                     cv->sex="\xe5\xa5\xb3";
                     qDebug()<<"\xe5\xa5\xb3\xe6\x80\xa7";
                 }


                 //
                 pHous->pCustomerVOs.append(cv);

             }//




             //联系地址
             pHous->adress= ws->read(i,adress).toString();
             //建筑面积
             pHous->buildingArea= QString::number(ws->read(i,building).toFloat());
             //套内面积
             pHous->insideArea= QString::number(ws->read(i,indsier).toFloat());
             //分摊面积
             pHous->sharingArea= QString::number(ws->read(i,share).toFloat());
             //服务费
             pHous->service = "3\xe5\x85\x83/\xe3\x8e\xa1 ";
             pHous->service.append(QString::number(int(ws->read(i,building).toFloat()*3)));
             pHous->service.append("\xe5\x85\x83");
             //总层数
             pHous->level =  ws->read(i,level).toString();
             //房款
             pHous->amout = ws->read(i,amount).toString();
             pHous->amout_cn = ConverToChinese(pHous->amout);
             //
             qDebug()<<pHous->amout<<" \xe6\x88\xbf\xe6\xac\xbe:"<<pHous->amout_cn;

             //土地使用证号
             pHous->tdsyzh =  ws->read(i,tdsyzh).toString();
             //房地产权证号
             pHous->fdcqzh =  ws->read(i,fdcqzh).toString();
             //盖章日期
             pHous->gzrq =  ws->read(i,gzrq).toString();
             //房屋类型
             pHous->houseType=ws->read(i,fwlx).toString();

             //所在层
             pHous->curLevel.append("\xe9\x92\xa2\xe7\xad\x8b\xe6\xb7\xb7\xe5\x87\x9d\xe5\x9c\x9f\xe7\xbb\x93\xe6\x9e\x84");
             pHous->curLevel.append(ws->read(i,level).toString());
             pHous->curLevel.append("\xe5\xb1\x82");
             // qDebug()<<pHous->curLevel;
             //房屋位置
             QString pha = "";
             pha.append(lineAdress);
             if(buildingType==1)//住宅
             {
                QStringList qhl = pHous->buildNum.split("-");
                if(qhl.size()==2)
                {
                     pha.append(qhl.at(0)).append("\xe5\xb9\xa2").append(qhl.at(1)).append("\xe5\x8f\xb7\xe6\x88\xbf");
                }
                pHous->houseUsage="\xe4\xbd\x8f\xe5\xae\x85";
             }
             else if(buildingType==2)//车位
             {
                 pha.append(carAdress).append(ws->read(i,szc).toString()).append("\xe5\xb1\x82").append(pHous->buildNum).append("\xe5\x8f\xb7").append(pHous->houseType);
                pHous->houseUsage="\xe8\xbd\xa6\xe5\xba\x93";
             }
             else if(buildingType==3)//商铺
             {
                 pha.append(pHous->buildNum).append("\xe5\x8d\xa1");
                 pHous->houseUsage="\xe5\x95\x86\xe4\xb8\x9a";
             }
            // qDebug()<<str<<"  "<<ltr<<"  ="<<ql.count();
             pHous->houseAdress = pha;
             qDebug()<<pha;

        }

        if(ptipLabel!=NULL)
        {
            QString tipva;
            tipva.append(ptipStr);
            tipva.append(QString::number(countNum));
            ptipLabel->setText(tipva);
        }

        qDebug()<<rowcount<<"数量:"<<ptipStr;
        //qDebug()<<slist.at(i);


    }

    qDebug()<<"\xe6\x95\xb0\xe9\x87\x8f:"<<HouseProList.size();

}

void MainWindow::on_lineEdit_editingFinished()
{

}

void MainWindow::on_BtnWord_clicked()
{
    dotWordUrl = QFileDialog::getOpenFileName(this," \xe4\xba\xa7\xe6\x9d\x83\xe5\xae\xa1\xe6\x89\xb9\xe8\xa1\xa8","","Doc(*.doc)");
    if (dotWordUrl.isEmpty())
    {
       return;

    }
}


void MainWindow::on_BtnExcel_clicked()
{
    //读取ecel样板
    //
    dotExcelUrl= QFileDialog::getOpenFileName(this," \xe4\xba\xa7\xe6\x9d\x83\xe5\xae\xa1\xe6\x89\xb9\xe8\xa1\xa8","","Xlsx(*.xlsx)");
    //
    if (dotExcelUrl.isEmpty())
    {
       return;

    }

}

void MainWindow::on_BtnTarget_clicked()
{
    int count = HouseProList.size();
    //targetUrl
    //检查是否有该目录


    if(count>0)
    {
        if(ui->checkBox_Word->isChecked())
        {


        }
        QProgressDialog process(this);
        QString dlabel = "生成中";
        process.setLabelText(dlabel);
        process.setRange(0,count);
        process.setModal(true);
        process.setCancelButtonText("\xe5\x8f\x96\xe6\xb6\x88");
        for(int i=0;i<count;i++)
        {

            process.setValue(i);
            if(process.wasCanceled())
            {
                break;
            }
            HousePropertyVO* hpv = HouseProList.at(i);


            if(ui->checkBox_Excel->isChecked())
            {
                //生成表格Excel表格
                this->createExcel(hpv);
            }
            if(ui->checkBox_Word->isChecked())
            {
                //生成Word
                this->createWord(hpv);
            }

        }

        if(pDocument!= NULL)
        {
            pDocument->dynamicCall("Close (boolean)",false);
            pWord->dynamicCall("Quit()");
            delete pDocument;
            delete pDocuments;
            delete pWord;
            pDocument=NULL;
            pDocuments = NULL;
            pWord=NULL;
        }



    }

}

//设置生成位置
void MainWindow::on_BtnCreate_clicked()
{
//
   QString url= QFileDialog::getExistingDirectory(this);
   url.append("/");
   ui->lineEdit_6->setText(url);
   targetUrl = url;
   qDebug()<<"url:"<<url;
}

void MainWindow::createExcel(HousePropertyVO *vo)
{


    if(vo==NULL)
    {
        return;
    }
    //获取对应位置
    QDir* cfie = new QDir;
    if(!cfie->exists(targetUrl))
    {
        return;
    }

    CustomerVO* ps = vo->pCustomerVOs.at(0);
    qDebug()<<"cus Name:"<<ps->Name;
    if(ps->Name.isEmpty() && !ui->checkBox->isChecked())
    {
        return;
    }

    Document xlsx(dotExcelUrl);
    QXlsx::Worksheet* ws = (QXlsx::Worksheet*)xlsx.sheet("\xe5\xae\xa1\xe6\x89\xb9\xe8\xa1\xa8");
    if(ws!=NULL)
    {
        qDebug()<<"write:";
        WruteExcel(ws,"tab","lineEdit_srf",vo->cusNameStr);
        qDebug()<<"姓名："<<ps->Name;
        WruteExcel(ws,"tab","lineEdit_sfz",vo->cardStr);//身份证
        qDebug()<<"身份证："<<ps->CardNum;
        WruteExcel(ws,"tab","lineEdit_zz",vo->adress);//住址
        qDebug()<<"住址："<<vo->adress;
        WruteExcel(ws,"tab","lineEdit_zl",vo->houseAdress);//房屋坐落
        qDebug()<<"房屋坐落："<<vo->houseAdress;
        WruteExcel(ws,"tab","lineEdit_fdczh",vo->fdcqzh);//房地产证
        qDebug()<<"房产证："<<vo->fdcqzh;
        WruteExcel(ws,"tab","lineEdit_tdsyzh",vo->tdsyzh);//土地证
        qDebug()<<"土地证："<<vo->tdsyzh;
        WruteExcel(ws,"tab","lineEdit_cs",vo->curLevel);
        qDebug()<<"当前层："<<vo->curLevel;
        WruteExcel(ws,"tab","lineEdit_jzmj",vo->buildingArea);
        qDebug()<<"建筑面积："<<vo->buildingArea;
        WruteExcel(ws,"tab","lineEdit_jyf",vo->service);
        qDebug()<<"房款"<<vo->amout_cn;
        WruteExcel(ws,"tab","lineEdit_fk",vo->amout_cn);
        qDebug()<<"服务费："<<vo->service;
        WruteExcel(ws,"tab","lineEdit_zrrq",vo->gzrq);
        WruteExcel(ws,"tab","lineEdit_srrq",vo->gzrq);

        qDebug()<<"save as";
        QString turl = "";




        turl.append(targetUrl);
        turl.append("\xe4\xba\xa4\xe6\x98\x93\xe5\xae\xa1\xe6\x89\xb9\xe8\xa1\xa8");
        QDir* fie = new QDir;
        if(!fie->exists(turl))
        {
            fie->mkdir(turl);
        }
        turl.append("/");
        turl.append(vo->houseAdress);
        turl.append("\xe4\xba\xa4\xe6\x98\x93\xe5\xae\xa1\xe6\x89\xb9\xe8\xa1\xa8.xlsx");
        qDebug()<<"Url："<<turl;
        xlsx.saveAs(turl);
    }


}

void MainWindow::WruteExcel(Worksheet *ws,QString wstr, QString pos, QString value)
{

    QWidget* tab = ui->tabWidget->findChild<QWidget*>(wstr);
    if(tab==NULL)
    {
        qDebug()<<" tab is NULL : key-"<<wstr;
    }
    QLineEdit  *plineEdit=tab->findChild<QLineEdit *>(pos);
    if(plineEdit==NULL)
    {
        qDebug()<<"plineEdit is NULL :key- "<<pos;
    }
    QList<int> kls = this->StrToInts(plineEdit->text());
    ws->write(kls.at(1),kls.at(0),value);

}

void MainWindow::WriteWord( QString pos, QString value)
{
    QWidget* tab = ui->tabWidget->findChild<QWidget*>("tab_2");
    QLineEdit  *plineEdit=tab->findChild<QLineEdit *>(pos);
    if(plineEdit==NULL)
    {
        qDebug()<<"plineEdit is NULL :key- "<<pos;
    }
    qDebug()<<plineEdit->text()<<":"<<value;
    QAxObject *bookmark_code = this->pDocument->querySubObject("Bookmarks(QVariant)",plineEdit->text());
    if(bookmark_code==NULL)
    {
        return;
    }
    if(!bookmark_code->isNull())
    {
        bookmark_code->dynamicCall("Select(void)");
        bookmark_code->querySubObject("Range")->setProperty("Text",value);
    }
    else
    {
        qDebug()<<"nono null";
    }
}

QString MainWindow::ConverToChinese(QString value)
{

    //std::string s = x.ToString("#L#E#D#C#K#E#D#C#J#E#D#C#I#E#D#C#H#E#D#C#G#E#D#C#F#E#D#C#.0B0A");
    //std::string d = Regex.Replace(s, @"((?<=-|^)[^1-9]*)|((?'z'0)[0A-E]*((?=[1-9])|(?'-z'(?=[F-L\.]|$))))|((?'b'[F-L])(?'z'0)[0A-L]*((?=[1-9])|(?'-z'(?=[\.]|$))))", "${b}${z}");
   // return Regex.Replace(d, ".", m => "负元空零壹贰叁肆伍陆柒捌玖空空空空空空空分角拾佰仟萬億兆京垓秭穰"[m.Value[0] - '-'].ToString());
     QString str = "零仟零佰零拾零万零仟零佰零拾零亿零仟零佰零拾零万零仟零佰零拾零元零角零分";
     QString vStr ="零壹贰叁肆伍陆柒捌玖";
    //5214684
     QString temp;
     temp.append(value);
    if(!temp.contains(".",Qt::CaseInsensitive))
    {

        temp=temp.append("00");
    }
    temp = temp.replace(".","");
    int cnt = temp.size();
    int cklen = str.size();
    int indx = 0;

    QStringList temparr;
    for (int i = 0; i < cnt; i++)
    {
        temparr << temp.mid(i, 1);
    }

    QStringList varr;
    for (int i = 0; i < vStr.size(); i++)
    {
        varr << vStr.mid(i, 1);
    }


    for(int i=cnt-1;i>=0;i--)
    {
        indx+=2;
        QString v= temparr.at(i);

        int kl = v.toInt();

        QString jc = varr.at(kl);
        //
        temp.mid(i,1);
        str.replace(cklen-indx,1,jc);
    }
    cnt = cnt*2;
    str = str.right(cnt);

    return str;
}





void MainWindow::createWord(HousePropertyVO *vo)
{
    QDir* cfie = new QDir;
    if(!cfie->exists(targetUrl))
    {
        return;
    }

    CustomerVO* ps = vo->pCustomerVOs.at(0);
    qDebug()<<"cus Name:"<<ps->Name;
    if(ps->Name.isEmpty() && !ui->checkBox->isChecked())
    {
        return;
    }


    //
    qDebug()<<"carete Word";
    pWord = new QAxWidget("Word.Application",0,Qt::MSWindowsOwnDC);
    pWord->setProperty("Visible",false);
    pDocuments = pWord->querySubObject("Documents");
    pDocuments->dynamicCall("Add(QString)",dotWordUrl);
    pDocument = pWord->querySubObject("ActiveDocument");
    //获取位置
    /*
    QAxObject *bookmark_code = this->pDocument->querySubObject("Bookmarks(QVariant)","主申请人");
    qDebug()<<"Test Word";
    if(!bookmark_code->isNull())
    {
        bookmark_code->dynamicCall("Select(void)");
        bookmark_code->querySubObject("Range")->setProperty("Text","aaaaaa");
    }
    */



    CustomerVO* v = vo->pCustomerVOs.at(0);
    qDebug()<<"cus Name:"<<v->Name;
    this->WriteWord("lineEdit_ssqr",v->Name);
    this->WriteWord("lineEdit_ssfz1",v->CardNum);
    this->WriteWord("lineEdit_sxb1",v->sex);
    this->WriteWord("lineEdit_scs1",v->bridDate);
    //
    qDebug()<<"======\xe8\xbf\x99\xe6\x98\xaf";

    QString feStr = "";
    if(vo->pCustomerVOs.size()==1)
    {
        feStr="\xe5\x8d\x95\xe7\x8b\xac\xe6\x89\x80\xe6\x9c\x89";
    }
    else if(vo->pCustomerVOs.size()==2)
    {
        feStr="\xe5\x85\xb1\xe5\x90\x8c\xe5\x85\xb1\xe6\x9c\x89";
    }
    else
    {
        feStr="\xe6\x8c\x89\xe4\xbb\xbd\xe5\x85\xb1\xe6\x9c\x89";
    }

    //客户
    for(int i=1;i<vo->pCustomerVOs.size();i++)
    {
        CustomerVO* sv = vo->pCustomerVOs.at(i);
        if(i==1)
        {
            this->WriteWord("lineEdit_sxm2",sv->Name);
            this->WriteWord("lineEdit_ssfz2",sv->CardNum);
            this->WriteWord("lineEdit_sxb2",sv->sex);
            this->WriteWord("lineEdit_scs2",sv->bridDate);
            this->WriteWord("lineEdit_sgj2","\xe4\xb8\xad\xe5\x9b\xbd");
            //lineEdit_sfe2
            this->WriteWord("lineEdit_sfe2",feStr);
            this->WriteWord("lineEdit_sdz2",vo->adress);
        }
        else if(i==2)
        {
            this->WriteWord("lineEdit_sxm3",sv->Name);
            this->WriteWord("lineEdit_ssfz3",sv->CardNum);
            this->WriteWord("lineEdit_sxb3",sv->sex);
            this->WriteWord("lineEdit_scs3",sv->bridDate);
            this->WriteWord("lineEdit_sgj3","\xe4\xb8\xad\xe5\x9b\xbd");
            this->WriteWord("lineEdit_sfe3",feStr);
            this->WriteWord("lineEdit_sdz3",vo->adress);
        }

    }
    //

    //this->WriteWord("lineEdit_sfh",vo->houseNum);
    //详细地址
    this->WriteWord("lineEdit_sxxdz",vo->adress);
    this->WriteWord("lineEdit_slxdh",vo->phone);
    this->WriteWord("lineEdit_sfe",feStr);
    //房屋坐落
    this->WriteWord("lineEdit_sfwzl",vo->houseAdress);
    //层数
    this->WriteWord("lineEdit_scs",vo->level);
    //建筑面积
    this->WriteWord("lineEdit_sjzmj",vo->buildingArea);
    //套内面积
    //this->WriteWord("lineEdit_stnmj",vo->insideArea);
    //房屋用途lineEdit_sfwyt
    this->WriteWord("lineEdit_sfwyt",vo->houseUsage);





    //保存
    //
    QString turl = "";

    turl.append(targetUrl);
    turl.append("\xe7\x94\xb3\xe8\xaf\xb7\xe4\xb9\xa6");
    QDir* fie = new QDir;
    if(!fie->exists(turl))
    {
        fie->mkdir(turl);
    }
    turl.append("/");
    turl.append(vo->houseAdress);
    turl.append("申请书.doc");
    qDebug()<<"Url："<<turl;
    pDocument->dynamicCall("SaveAs (const QString&)",turl);
    pDocument->dynamicCall("Close (boolean)",false);
    pWord->dynamicCall("Quit()");
    delete pDocument;
    delete pDocuments;
    delete pWord;
    pDocument=NULL;
    pDocuments = NULL;
    pWord=NULL;
}

int MainWindow::MoreCharToInt(QString value)
{

    int rtn = 0;
    int powIndex = 0;

    for (int i = value.count() - 1; i >= 0; i--)
    {
        int tmpInt =value.at(i).unicode();

       rtn = rtn*26+tmpInt-65+1;
   }


    return rtn;
}

QList<int> MainWindow::StrToInts(QString value)
{
    QList<int> res;
    //获取数字
    QString ol="";
    ol.append(value);
    QString va = value.replace(QRegExp("[0-9]"),"");
    qDebug()<<"sss:"<<va;
    res.append(MoreCharToInt(va));
    va = ol.replace(QRegExp("[^0-9]"),"");
    res.append(va.toInt());
    return res;
}









